<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/ydui.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/base.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/style.css" />
    <link rel="stylesheet" href="/${BasePath}/static/mobile/css/swiper.min.css" />  
    <title>半岛云</title>  
</head>
<body>
	<div class="wrap">
		<!--标题栏-->
		<div class="fixed_top">
			<div class="top-l"><a href="javascript:window.history.back()"><i class="icons">&#xe626;</i></a></div>
			<h1>收货地址</h1>
			<div class="top-r"><a href="javascript:;" class="bjbtn">管理</a></div>
		</div>
		
		<div class="container">
			<ul class="address_list">
			<#list address as add>
	  			<li data-id="${add.id!''}" class="checks">
	  				<div class="dzcheck"><i class="icons unchecked">&#xe619;</i><i class="icons checked">&#xe607;</i></div>
	  				<h4><#if add.isDefault=="1">(默认)</#if> <span>${add.name!""}</span><span>${add.phone!""}</span></h4>
	  				<p>${add.provance!""}${add.city!""}${add.area!""}${add.address!""}</p>
	  				<div class="delete" data-id="${add.id!''}"><i class="icons">&#xe649;</i></div>
	  			</li>
	  		</#list>
	  		</ul>
  		</div>
  		
  		<ul class="address_tab">
  			<li><a href="/${BasePath}/main/insertAddress">新建地址</a></li>
  			<li><a href="javascript:;" class="swmr">设为默认</a></li>
  		</ul>
	</div>
	
		  
		<!--导航栏-->
        <#include "/common/foot.html">
</body>
 

<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.flexible.js"></script>
<script type="text/javascript" src="/${BasePath}/static/mobile/js/ydui.js"></script>
<script type="text/javascript">
    $(function(){
    	//eruda.init();
        $("body").on("click",".address_list li",function(){
	    	$(this).addClass("active").siblings().removeClass();
	    })
        
        $("body").on("click",".bjbtn",function(){
	       $(".delete").fadeToggle() 
	    })
        
        
        $("body").on("click",".delete",function(){
	       $(this).parents("li").remove()
	    })
        
	    $(".delete").click(function(){
	        $.ajax({
	            type: 'post',
	            url: "/${BasePath}/main/deleteAddress",
	            data: {"id":$(this).attr('data-id')},
	            dataType: 'json',
                error: function(request) {
                	YDUI.dialog.alert('系统错误，请稍后再试！');
                },
	            success: function(data){
	                if (data.code == "1"){
	                	YDUI.dialog.toast(data.msg, 'success', 2000, function () {
	                		location.reload();
	                	});
	                }else{
	                	YDUI.dialog.alert('系统错误，请稍后再试！');
	                }
	            }
	        });	    	
	    })
	    
	    $(".swmr").click(function(){
            var addId=0;
	    	$(".checks.active").each(function(index,item){
	    		addId=$(this).attr('data-id');
	    	})
	    	if(addId===0){                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
	    		YDUI.dialog.alert('请选择有效数据！');
	    		return;
	    	}
	        $.ajax({
	            type: 'post',
	            url: "/${BasePath}/main/defaultAddress",
	            data: {"id":addId},
	            dataType: 'json',
                error: function(request) {
                	YDUI.dialog.alert('系统错误，请稍后再试！');
                },
	            success: function(data){
	                if (data.code == "1"){
	                	YDUI.dialog.toast(data.msg, 'success', 2000, function () {
	                		location.reload();
	                	});
	                }else{
	                	YDUI.dialog.alert('系统错误，请稍后再试！');
	                }
	            }
	        });
	    })    
        
	})
</script>
</html>